package com.wbt.jdk.function;

import java.util.function.Function;

/**
 * @program: src-study
 * @description: function
 * @author: Wang·Baotong
 * @create: 2021-07-01 11:24
 */
public class TestFunction {

    public static void main(String[] args) {

        System.out.println(testFunction(2,i -> i * 2 + 1));  // 2*2+1=5
        System.out.println(testFunction1(2,i -> i * 2 + 1,j -> j * j)); // 2*2=4 ;  4*2+1=9
        System.out.println(testFunction2(2,i -> i * 2 + 1,j -> j * j)); // 2*2+1=5 ; 5*5=25
    }

    public static int testFunction(int i, Function<Integer,Integer> function) {
        return function.apply(i);
        //return function.apply(function.apply(i));
        // return function.compose(function).apply(i);
        //return function.andThen(function).apply(i);
    }

    public static int testFunction1(int i, Function<Integer,Integer> function1,Function<Integer,Integer> function2) {

        return function1.compose(function2).apply(i);
    }
    public static int testFunction2(int i, Function<Integer,Integer> function1,Function<Integer,Integer> function2) {

        return function1.andThen(function2).apply(i);
    }

}
